/**
 * Created with JetBrains WebStorm.
 * User: gcw
 * Date: 14-6-17
 * Time: 下午12:18
 * To change this template use File | Settings | File Templates.
 */
$(function(){
    /**
     * $.delete 仿照$.get 扩展的delete请求
     * 必须传入的参数有：请求路径(url)、处理请求结果的回调函数(call)
     * 可选参数有：请求时传递的数据(data，为对象格式)、请求是否为异步请求的布尔值(async，默认为true)
     * 返回的数据默认是字符串处理
     * 传入参数的顺序为：url, [data], call, [async]
     */
    $.delete = function(){
        var len = arguments.length,
            url = "",
            data = {},
            call = null,
            async = true;
        if(len == 4){
            url = arguments[0];
            data = arguments[1];
            call = arguments[2];
            async = arguments[3];
        }else if(len == 3){
            if(typeof arguments[2] === "boolean"){
                url = arguments[0];
                call = arguments[1];
                async = arguments[2];
            }else{
                url = arguments[0];
                data = arguments[1];
                call = arguments[2];
            }
        }else if(len == 2){
            url = arguments[0];
            call = arguments[1];
        }
        $.ajax({
            type: "DELETE",
            url: url,
            data: data,
            success: call,
            async: async,
            dataType: "text"
        });
    };

    /**
     * $.put 仿照$.get 扩展的put请求
     * 必须传入的参数有：请求路径(url)、处理请求结果的回调函数(call)、请求时传递的数据(data，为对象格式)
     * 可选参数有：请求是否为异步请求的布尔值(async，默认为true)
     * 返回的数据默认是字符串处理
     * 传入参数的顺序为：url, data, call, [async]
     */
    $.put = function(){
        var len = arguments.length,
            url = "",
            data = {},
            call = null,
            async = true;
        if(len == 4){
            url = arguments[0];
            data = arguments[1];
            call = arguments[2];
            async = arguments[3];
        }else if(len == 3){
            url = arguments[0];
            data = arguments[1];
            call = arguments[2];
        }
        $.ajax({
            type: "PUT",
            url: url,
            data: data,
            success: call,
            async: async,
            dataType: "text"
        });
    };
});
